﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QUAN_LY_NGAN_HANG_CAU_HOI_TRAC_NGHIEM
{
    public partial class FrmTraCuuCauHoi : Form
    {
        public FrmTraCuuCauHoi()
        {
            InitializeComponent();
        }

        private TraCuuCauHoiPresenter pre;
        private DataTable kq;
        private LinhVucBUS[] linhvuc;
        private MucDoBUS[] mucdo;
        private GiaoVienDAL[] giaovien;

        private void FrmTraCuuCauHoi_Load(object sender, EventArgs e)
        {
            cboMucDo.Items.Add("None");
            cboLinhVuc.Items.Add("None");
            cboGiaoVien.Items.Add("None");

            pre = new TraCuuCauHoiPresenter();
            linhvuc = pre.ListLinhVuc();
            for (int i = 0; i < linhvuc.Count(); i++)
                cboLinhVuc.Items.Add(linhvuc[i].ChuThich);

            mucdo = pre.ListMucDo();
            for (int i = 0; i < mucdo.Count(); i++)
                cboMucDo.Items.Add(mucdo[i].ChuThich);

            giaovien = pre.LayTatCaGiaoVien();
            for (int i = 0; i < giaovien.Count(); i++)
                cboGiaoVien.Items.Add(giaovien[i].HoGiaoVien + " " + giaovien[i].TenGiaoVien);

            cboGiaoVien.Text = cboLinhVuc.Text = cboMucDo.Text = "None";
            lblMucDo.Text = lblLinhVuc.Text = lblGiaoVien.Text = "";

            this.Left = 50;
            this.Top = 0;

            this.helpProvider1.SetHelpNavigator(this, HelpNavigator.Topic);
            this.helpProvider1.SetHelpKeyword(this, "TraCuCauHi.html");
        }

        private void cboGiaoVien_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboGiaoVien.SelectedIndex > -1)
                lblGiaoVien.Text = cboGiaoVien.SelectedItem.ToString();
        }

        private void cboMucDo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboMucDo.SelectedIndex > -1)
                lblMucDo.Text = cboMucDo.SelectedItem.ToString();
        }

        private void cboLinhVuc_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboLinhVuc.SelectedIndex > -1)
                lblLinhVuc.Text = cboLinhVuc.SelectedItem.ToString();
        }

        private void linkTraCuu_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Guid MaGV, MaLV, MaMD;
            int index;
            index = cboGiaoVien.SelectedIndex;
            if (index > 0)
                MaGV = giaovien[index - 1].MaSoGiaoVien;
            else
                MaGV = Guid.Empty;
            index = cboLinhVuc.SelectedIndex;
            if (index > 0)
                MaLV = linhvuc[index-1].MaSoLinhVuc;
            else
                MaLV = Guid.Empty;
            index = cboMucDo.SelectedIndex;
            if (index > 0)
                MaMD = mucdo[index-1].MaSoMucDo;
            else
                MaMD = Guid.Empty;

            kq = pre.ListCauHoiTheoDieuKien(MaGV, MaLV, MaMD);
            dgvDanhSach.DataSource = kq;
            dgvDanhSach.Columns["MaSoCauHoi"].Visible = false;
        }

        private void linkThoat_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Close();
        }

        private void dgvDanhSach_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Guid macauhoi = (Guid)dgvDanhSach["MaSoCauHoi", e.RowIndex].Value;
            dgvDapAn.DataSource = pre.LayDapAnTheoCauHoi(macauhoi);
            dgvDapAn.Columns["DapAnDung"].Visible = false;
            dgvDapAn.Columns["MaSoCauHoi"].Visible = false;
            txtNoiDung.Text = (string)dgvDanhSach[1, e.RowIndex].Value.ToString();
        }
    }
}
